package com.growthsee.rider.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.growthsee.common.annotation.Log;
import com.growthsee.common.core.controller.BaseController;
import com.growthsee.common.core.domain.AjaxResult;
import com.growthsee.common.core.page.PageDomain;
import com.growthsee.common.core.page.TableDataInfo;
import com.growthsee.common.enums.BusinessType;
import com.growthsee.common.utils.SecurityUtils;
import com.growthsee.common.utils.StringUtils;
import com.growthsee.rider.domain.RiderIllegal;
import com.growthsee.rider.enumeration.YesNoEnum;
import com.growthsee.rider.param.RiderIllegalParam;
import com.growthsee.rider.service.IRiderIllegalService;
import com.growthsee.rider.utils.BeanUtilsExt;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 【请填写功能名称】Controller
 *
 * @author growthsee
 * @date 2021-08-08
 */

@AllArgsConstructor
@Api("骑手违法")
@RestController
@RequestMapping("/rider/illegal")
public class RiderIllegalController extends BaseController
{
    private final IRiderIllegalService iRiderIllegalService;

    @Log(title = "【接受交警推送的數據】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiderIllegal riderIllegal) {
        riderIllegal.setCreateTime(new Date());
        riderIllegal.setCreateBy(SecurityUtils.getLoginUser().getUser().getUserId().toString());
        return toAjax(iRiderIllegalService.save(riderIllegal));
    }



    @ApiOperation(value = "分页查询骑手", notes = "分页查询骑手")
    @GetMapping
    public TableDataInfo query(PageDomain page, RiderIllegalParam baseParam) {
        LambdaQueryWrapper<RiderIllegal> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(RiderIllegal::getDelFlag, YesNoEnum.NO.getValue());
        if(StringUtils.isNotEmpty(baseParam.getKeywords())){
            queryWrapper.and(query->query
                    .like(RiderIllegal::getName,baseParam.getKeywords())
                    .or()
                    .like(RiderIllegal::getIdcard,baseParam.getKeywords()));
        }
        if(StringUtils.isNotEmpty(baseParam.getPunishType())){
            queryWrapper.eq(RiderIllegal::getPunishType,baseParam.getPunishType());
        }
        Page page1 = iRiderIllegalService.page(new Page<>(page.getPageNum(),page.getPageSize()), queryWrapper);
        Page<RiderIllegal> pageData = BeanUtilsExt.copyPageData(page1, RiderIllegal.class);

        return getDataTable(pageData.getRecords(),pageData.getTotal());
    }


}
